package com.uniview.entity.vo;

import java.util.ArrayList;
import java.util.List;

import com.uniview.enums.EOrderMode;

/**
 * 查询条件组装
 * 
 * @author admin
 * 
 */
public class QueryBuilder {

	/**
	 * 实体对象名
	 */
	private String entityName = null;

	/**
	 * 查询条件
	 */
	private List<Query> queryList = new ArrayList<Query>();

	/**
	 * 排序字段
	 */
	private String[] orderCols = null;

	/**
	 * 排序方式(默认升序)
	 */
	private EOrderMode orderMode = null;

	public QueryBuilder(String entityName) {
		this.entityName = entityName;
	}

	/**
	 * 添加查询条件
	 * 
	 * @param query
	 */
	public List<Query> add(Query... query) {
		if (query != null) {
			for (Query q : query) {
				if (q != null) {
					queryList.add(q);
				}
			}
		}
		return queryList;
	}

	public String[] getOrderCols() {
		return orderCols;
	}

	public void setOrderCols(String... orderCols) {
		this.orderCols = orderCols;
	}

	public EOrderMode getOrderMode() {
		return orderMode == null ? EOrderMode.ASC : orderMode; // 默认升序
	}

	public void setOrderMode(EOrderMode orderMode) {
		this.orderMode = orderMode;
	}

	public List<Query> getQueryList() {
		return queryList;
	}

	public String getEntityName() {
		return entityName;
	}

	public void setEntityName(String entityName) {
		this.entityName = entityName;
	}

}
